package org.finjic.callback.container;

import org.finjic.utils.ReflectionUtils;

import java.util.Set;

/**
 * User: Taras
 * Date: 02.12.12
 * Time: 13:27
 */
public class ContainerCallbackProcessor {

    public void start(){
        Set<Class<? extends ContainerStartup>> startupListeners = ReflectionUtils.getSubclasses("org.finjic", ContainerStartup.class);
        for(Class<? extends ContainerStartup> listener : startupListeners){
            try{
                listener.getMethod("onStart").invoke(null);
            } catch (Exception e){
                throw new RuntimeException(e);
            }
        }
    }

    public void shutdown(){
        Set<Class<? extends ContainerShutdown>> shutdownListeners = ReflectionUtils.getSubclasses("org.finjic", ContainerShutdown.class);
        for(Class<? extends ContainerShutdown> listener : shutdownListeners){
            try{
                listener.getMethod("onShutdown").invoke(null);
            } catch (Exception e){
                throw new RuntimeException(e);
            }
        }
    }
}
